﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2.Model
{
    class Aset
    {

        int id;
        string nama;
        int harga;
        int mortisasi;
        int jumlah;
        DateTime tgl_produksi;
        DateTime tgl_expired;
        int id_cabang;

        public Aset()
        {

        }

        public Aset(string _Nama)
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM aset WHERE nama = '" + _Nama + "'";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];

            id = (int)dr[0];
            nama = (string)dr[1];
            harga = (int)dr[2];
            mortisasi = (int)dr[3];
            jumlah = (int)dr[4];
            tgl_produksi = (DateTime)dr[5];
            tgl_expired = (DateTime)dr[6];
            id_cabang = (int)dr[7];
            
            db.Close();
        }

        public static ArrayList daftarAset(int _Cabang)
        {
            ArrayList a = new ArrayList();
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            object[] o = new object[3];
            string sql = "SELECT * FROM aset";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr;
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                dr = dt.Rows[i];

                o[0] = dr[0];
                o[1] = dr[1];
                o[2] = dr[2];
                a.Add(o.Clone());
            }

            db.Close();

            return a;
        }

        public void addAset()
        {
            Database db = new Database();
            string sql = "INSERT INTO aset(nama, harga, mortisasi, jumlah, tgl_produksi, tgl_expired, id_cabang) VALUES ('" + nama + "','" + harga.ToString() +
                    "','" + mortisasi.ToString() + "','" + jumlah.ToString() + "'," + tgl_produksi.ToString() + ",'" + tgl_expired.ToString() + "','" + id_cabang.ToString() + "')";

            db.Open();
            db.ExecuteNonQuery(sql);
            db.Close();

        }

        public void UpdateAset()
        {
        }

        public void DeleteAset()
        {
        }

    }
}
